def countdown(n):
    while n > 0:
        print('return ' + str(n))
        yield n
        n -= 1
        if n == 3:
            print("end")
            break

# 使用生成器函数创建一个生成器对象
c = countdown(5)

c2 = countdown(5)

# 输出生成器对象的元素
for i in c:
    print(i)  # 输出：5 4 3 2 1
    print('test1')  # 输出：5 4 3 2 1

for i2 in c2:
    print(i2)  # 输出：5 4 3 2 1
    print('test2')  # 输出：5 4 3 2 1